<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-form-item label="主键" prop="id">
        <el-input v-model="dataForm.id" placeholder="主键"></el-input>
      </el-form-item>
      <el-form-item label="展品名称" prop="name">
        <el-input v-model="dataForm.name" placeholder="展品名称"></el-input>
      </el-form-item>
      <el-form-item label="品牌" prop="brand">
        <el-input v-model="dataForm.brand" placeholder="品牌"></el-input>
      </el-form-item>
      <el-form-item label="市场价" prop="price">
        <el-input v-model="dataForm.price" placeholder="市场价"></el-input>
      </el-form-item>
      <el-form-item label="现场价" prop="exhPrice">
        <el-input v-model="dataForm.exhPrice" placeholder="现场价"></el-input>
      </el-form-item>
      <el-form-item label="简介" prop="intro">
        <el-input v-model="dataForm.intro" placeholder="简介"></el-input>
      </el-form-item>
      <el-form-item label="内容描述" prop="content" style="height: 300px">
        <editor v-model="dataForm.content" :init="{ height: 300 }"></editor>
      </el-form-item>
      <el-form-item label="头图url" prop="pictureUrl">
        <el-input v-model="dataForm.pictureUrl" placeholder="头图url"></el-input>
      </el-form-item>
      <el-form-item label="上传会员id" prop="accountId">
        <el-input v-model="dataForm.accountId" placeholder="上传会员id"></el-input>
      </el-form-item>
      <el-form-item label="展品预约量" prop="bespeak">
        <el-input v-model="dataForm.bespeak" placeholder="展品预约量"></el-input>
      </el-form-item>
      <el-form-item label="上传公司" prop="company">
        <el-input v-model="dataForm.company" placeholder="上传公司"></el-input>
      </el-form-item>
      <el-form-item label="展会ID" prop="exhid">
        <el-input v-model="dataForm.exhid" placeholder="展会ID"></el-input>
      </el-form-item>
      <el-form-item label="展会名称" prop="exh">
        <el-input v-model="dataForm.exh" placeholder="展会名称"></el-input>
      </el-form-item>
      <el-form-item label="展馆号" prop="exhHall">
        <el-input v-model="dataForm.exhHall" placeholder="展馆号"></el-input>
      </el-form-item>
      <el-form-item label="展位号" prop="exhStand">
        <el-input v-model="dataForm.exhStand" placeholder="展位号"></el-input>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t("confirm") }}</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts">
import { defineComponent, reactive } from "vue";
import baseService from "@/service/baseService";
import { useDebounce } from "@/utils/utils";
import Tinymce from "@/components/tinymce";
export default defineComponent({
  components: { editor: Tinymce },
  setup() {
    return reactive({
      visible: false,
      dataForm: {
        id: "",
        name: "",
        brand: "",
        price: "",
        exhPrice: "",
        intro: "",
        content: "",
        pictureUrl: "",
        accountId: "",
        bespeak: "",
        company: "",
        exhid: "",
        exh: "",
        exhHall: "",
        exhStand: "",
        createTime: ""
      }
    });
  },
  computed: {
    dataRule() {
      return {};
    }
  },
  created() {
    this.dataFormSubmitHandle = useDebounce(this.dataFormSubmitHandle);
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataFormRef"].resetFields();
        if (this.dataForm.id) {
          this.getInfo();
        }
      });
    },
    // 获取信息
    getInfo() {
      baseService.get("/noc/texhibit/" + this.dataForm.id).then((res) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.dataForm = res.data;
      });
    },
    // 表单提交
    dataFormSubmitHandle() {
      this.$refs["dataFormRef"].validate((valid: boolean) => {
        if (!valid) {
          return false;
        }
        (!this.dataForm.id ? baseService.post : baseService.put)("/noc/texhibit", this.dataForm).then((res) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message({
            message: this.$t("prompt.success"),
            type: "success",
            duration: 500,
            onClose: () => {
              this.visible = false;
              this.$emit("refreshDataList");
            }
          });
        });
      });
    }
  }
});
</script>
